/**
 * Created by zdx  on 2016/8/26.
 *
 *
 */

define([ 'controller'], function ( c) {

    return {
        /* ---- 获取通用信息 ---- */
         getCommonInfos : function (param) {
            if(c.getValues(param)){
                return JSON.parse(c.getValues(param));
            }else{
                return {err:'1',msg:'未找到相关信息'}
            }
        },
         commonInfosRefresh : function (async) {
            //获取aircraft信息
            if(c.getToken()){

                this.commonInfosRefreshAircraft(async);
                //获取pilot信息
                this.commonInfosRefreshPilot(async);
                //获取company信息
                this.commonInfosRefreshCompany(async);
            }
        },
         commonInfosRefreshAircraft : function (async) {
            //获取Aircraft信息
            var asyncValue = true;
            if(async || async==false){
                asyncValue = false;
            }
            c.ajax({
                async:asyncValue,
                url:'suggest',
                data:{
                    action:'aircraft'
                },
                success:function(results){
                    c.setValues('aircraft',JSON.stringify(results));
                }
            });
        },
         commonInfosRefreshPilot :function (async) {
            //获取pilot信息
            var asyncValue = true;
            if(async || async==false){
                asyncValue = false;
            }
            c.ajax({
                async:asyncValue,
                url:'suggest',
                data:{
                    action:'pilot'
                },
                success:function(results){
                    c.conLog(results);
                    c.setValues('pilot',JSON.stringify(results));
                    return results;
                }
            });
        },
        commonInfosRefreshCompany: function (async) {
            //获取company信息
            var asyncValue = true;
            if(async || async==false){
                asyncValue = false;
            }
            c.ajax({
                async:asyncValue,
                url:'suggest',
                data:{
                    action:'company'
                },
                success:function(results){
                    c.setValues('company',JSON.stringify(results));
                }
            });
        },
         commonInfosRefreshOne: function (param,asyncValue) {
            //刷新action为param的通用数据
            var asyncValue = true;
            if(async || async==false){
                asyncValue = false;
            }
            c.ajax({
                async:asyncValue,
                url:'suggest',
                data:{
                    action:'param'
                },
                success:function(results){
                    c.setValues('param',JSON.stringify(results));
                }
            });
        }
        /* ---- 获取通用信息 ---- */
    }
});